#!/bin/bash


MYSQL_PATH=/usr/local/mysql
MYSQL_DATA=$MYSQL_PATH/data
MYSQL_LOG=$MYSQL_PATH/logs
MYSQL_PASSWD=root123

# 0.验证系统类型
which apt &> /dev/null
if [  $? -eq 0 ]
then
    os=ubuntu
else 
    which yum &> /dev/null
    if [  $? -eq 0 ]
    then
        os=centos
    else
        echo "系统无法识别！！"
        exit
    fi
fi

echo "您的系统是："$os

# * 1.安装依赖
#   * CentOS7：yum 安装
#   * Ubuntu: apt 安装
# if [ $os = ubuntu ]
# then
#     sudo apt update
#     sudo apt install -y libaio1 libaio-dev libtinfo5 libncurses-dev libncurses5 libncurses5-dev libncursesw5 libncursesw5-dev libssl-dev
# elif [ $os = centos  ]
# then
#     yum install -y libaio libaio-devel ncurses ncurses-devel openssl openssl-devel
# else
#     echo "系统识别失败"
#     exit
# fi
# * 2.下载
#   * 成功：进行下一步，解压缩、安装、设置权限
#   * 失败：退出安装，提示失败原因

cd /usr/local/src

if [ -e /usr/local/src/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz ]
then
    echo "下载成功"
else
    wget http://192.168.56.200/Software/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
fi

md5=`md5sum /usr/local/src/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz | awk  '{print $1}'`

if [  $md5 = 2acb6d9f1e590ff66cc5bae2378a964b ]
then
    echo "校验！！"
else
    echo "校验失败！！"
    exit
fi

# * 3.解压缩
#   * 成功：进行下一步
#   * 失败：退出安装，提示失败原因

tar -xvf /usr/local/src/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz


# * 4.安装与初始化
#   * 成功：进行下一步
#   * 失败：退出安装，提示失败原因
# * 5.获取初始密码
#   * 成功：进行下一步
#   * 失败：退出安装，提示失败原因
# * 6.设置开机启动
#   * 成功：进行下一步
#   * 失败：退出安装，提示失败原因
# * 7.启动并验证
#   * 成功：进行下一步
#   * 失败：退出安装，提示失败原因
